package com.situ.mall.oop;

public class Person1 implements Cloneable{
    public Integer age;
    public int[] arr = {1, 2};

    public Person1(Integer age) {
        this.age = age;
    }

    @Override
    public Person1 clone() {
        try {
            //return (Person1) super.clone();
            Person1 person = (Person1) super.clone();
            person.arr = this.arr.clone();
            return person;
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) {
        Person1 p1 = new Person1(18);
        Person1 p2 = p1.clone();
        p2.age = 20;
        p2.arr[0] = 10;

        System.out.println(p1 == p2);//false
        System.out.println(p1.age);//18
        System.out.println(p1.arr[0]);//10
    }
}


